<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" session="false"%>

<%@include file="/common/skins/skin0/component.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%--
- Author(s): Robert
- Date: 2018-03-29 16:55:01
- Description:
    --%>
<head>
<title>新增任务</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="<%=request.getContextPath()%>/common/nui/nui.js"
	type="text/javascript">
	
</script>
</head>
<style>
.form_label {
	font-size: 12px;
}
</style>
<body>

	<!-- 标识页面是查看(query)、修改(edit)、新增(add) -->
	<input name="pageType" class="nui-hidden" />
	<div id="dataform1" style="padding-top: 5px;">
		<!-- hidden域 -->
		<input class="nui-hidden" name="zhmytask.taskId" />
		<table style="width: 100%; height: 15%; table-layout: fixed;"
			class="nui-form-table">
			<tr>
				<td class="form_label">任务标题:</td>
				<td colspan="1"><input class="nui-textbox" required="true"
					vtype="maxLength:10" name="zhmytask.taskTitle" /></td>
				<td class="form_label">任务类型:</td>
				<td colspan="1"><input class="nui-dictcombobox" required="true"
					dictTypeId="TASK_TYPE" name="zhmytask.taskType" /></td>
				
			</tr>
			<tr>
				<td class="form_label">所属项目:</td>
				<td colspan="1"><input id="lookup2" required="true" onvaluechanged="onDeptChanged"
					name="zhmytask.zhmyProject.projectId" class="nui-lookup"
					textField="projectName" valueField="projectId" popupWidth="auto"
					popup="#gridPanel" grid="#datagrid1" multiSelect="false" /></td>
				<td class="form_label">紧急程度:</td>
				<td colspan="1"><input class="nui-dictcombobox" required="true"
					dictTypeId="URGENT_DEGREE" name="zhmytask.taskLevel" /></td>
				<td class="form_label"></td>
				<td colspan="1"><a><button
							style='margin: 2px; background: #4caf50; color: #fff; text-align: center; display: inline-block; border-radius: 8px; padding: 4px 10px; border: none;'
							onclick='onOk()'>保存</button></a></td>
			</tr>
			<tr>
				<td class="form_label">接收人:</td>
				<td colspan="1">
					<!--  <input class="nui-textbox" name="zhmytask.taskSendee"/>--> <input
					id="lookup3" name="zhmytask.taskSendee" class="nui-lookup"
					textField="name" valueField="name" popupWidth="auto"
					popup="#gridPanel3" grid="#datagrid3" multiSelect="false" />
				</td>
				<td class="form_label">版本:</td>
				<td colspan="1"><input id="lookup5" required="true"
					name="zhmytask.zhmyVersionChange.vcId" class="nui-lookup"
					textField="vcVersionNumber" valueField="vcId" popupWidth="auto"
					popup="#gridPanel5" grid="#datagrid5" multiSelect="false" />
			</tr>
			<tr>
			</tr>
		</table>
		<div style="width: 100%; height: 80%;">
			<div>任务描述:</div>
			<div>
				<w:richtext id="id1" name="zhmytask.taskDescibe2"
					property="zhmytask.taskDescibe2" width="100%" height="500" />
			</div>
		</div>
	</div>

	<!--  look up 1 -->
	<div id="gridPanel" class="nui-panel" title="header" iconCls="icon-add"
		style="width: 450px; height: 250px;" showToolbar="true"
		showCloseButton="true" showHeader="false" bodyStyle="padding:0"
		borderStyle="border:0">
		<div property="toolbar"
			style="padding: 5px; padding-left: 8px; text-align: center;">
			<div style="float: left; padding-bottom: 2px;">
				<span>项目名称:</span> <input id="keyText" class="nui-textbox"
					style="width: 160px;" onenter="onSearchClick" /> <a
					class="nui-button" onclick="onSearchClick">查询</a> <a
					class="nui-button" onclick="onClearClick">清除</a>
			</div>
			<div style="float: right; padding-bottom: 2px;">
				<a class="nui-button" onclick="onCloseClick">关闭</a>
			</div>
			<div style="clear: both;"></div>
		</div>
		<div id="datagrid1" class="nui-datagrid"
			style="width: 100%; height: 100%;" borderStyle="border:0"
			showPageSize="false" showPageIndex="false" dataField="orgs"
			url="com.zhmy.xmgl.zhmytaskbiz.queryProjectId.biz.ext">
			<div property="columns">
				<div type="checkcolumn"></div>
				<div field="projectFounder" width="120" headerAlign="center"
					allowSort="true">创建人</div>
				<div field="projectName" width="120" headerAlign="center"
					allowSort="true">项目名称</div>
			</div>
		</div>
	</div>

	<!--  look up 3 -->
	<div id="gridPanel3" class="nui-panel" title="header"
		iconCls="icon-add" style="width: 450px; height: 250px;"
		showToolbar="true" showCloseButton="true" showHeader="false"
		bodyStyle="padding:0" borderStyle="border:0">
		<div property="toolbar"
			style="padding: 5px; padding-left: 8px; text-align: center;">
			<div style="float: left; padding-bottom: 2px;">
				<span>接收人:</span> <input id="keyText3" class="nui-textbox"
					style="width: 160px;" onenter="onSearchClick3" /> <a
					class="nui-button" onclick="onSearchClick3">查询</a> <a
					class="nui-button" onclick="onClearClick3">清除</a>
			</div>
			<div style="float: right; padding-bottom: 2px;">
				<a class="nui-button" onclick="onCloseClick3">关闭</a>
			</div>
			<div style="clear: both;"></div>
		</div>
		<div id="datagrid3" class="nui-datagrid"
			style="width: 100%; height: 100%;" borderStyle="border:0"
			showPageSize="false" showPageIndex="false" dataField="people"
			url="com.zhmy.xmgl.zhmyprojectmanage.getPeopleListOfProject.biz.ext?projectid=1">
			<div property="columns">
				<div type="checkcolumn"></div>
				<div field="name" width="120" headerAlign="center"
					allowSort="true">姓名</div>
			</div>
		</div>
	</div>
	
	<!--  look up 5 -->
	<div id="gridPanel5" class="nui-panel" title="header"
		iconCls="icon-add" style="width: 450px; height: 250px;"
		showToolbar="true" showCloseButton="true" showHeader="false"
		bodyStyle="padding:0" borderStyle="border:0">
		<div property="toolbar"
			style="padding: 5px; padding-left: 8px; text-align: center;">
			<div style="float: left; padding-bottom: 2px;">
				<span>接收人:</span> <input id="keyText5" class="nui-textbox"
					style="width: 160px;" onenter="onSearchClick5" /> <a
					class="nui-button" onclick="onSearchClick5">查询</a> <a
					class="nui-button" onclick="onClearClick5">清除</a>
			</div>
			<div style="float: right; padding-bottom: 2px;">
				<a class="nui-button" onclick="onCloseClick5">关闭</a>
			</div>
			<div style="clear: both;"></div>
		</div>
		<div id="datagrid5" class="nui-datagrid"
			style="width: 100%; height: 100%;" borderStyle="border:0"
			showPageSize="false" showPageIndex="false" dataField="orgs"
			url="com.zhmy.xmgl.zhmyprojectmanage.getVersionListOfProject.biz.ext">
			<div property="columns">
				<div type="checkcolumn"></div>
				<div field="vcVersionNumber" width="120" headerAlign="center"
					allowSort="true">版本名称</div>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		nui.parse();
		
		var outProjectid = 1;
		
		//选择接收人关于项目联动的处理函数
		function onDeptChanged(e) {
			var projectid = nui.getbyName("zhmytask.zhmyProject.projectId").getValue();
			outProjectid = projectid;
			console.log("projectid="+outProjectid);
			
		    var url = "com.zhmy.xmgl.zhmyprojectmanage.getPeopleListOfProject.biz.ext?projectid="+projectid;
		   nui.get("datagrid3").setUrl(url);
		   onSearchClick3();
		   onSearchClick5();
		}

		function saveData() {
			var content = $id("id1").getValue();

			var desc = content;

			var form = new nui.Form("#dataform1");
			form.setChanged(false);
			//保存
			var urlStr = "com.zhmy.xmgl.zhmytaskbiz.addZhmyTask.biz.ext";
			var pageType = nui.getbyName("pageType").getValue();//获取当前页面是编辑还是新增状态
			//编辑
			if (pageType == "edit") {
				urlStr = "com.zhmy.xmgl.zhmytaskbiz.updateZhmyTask.biz.ext";
			}
			form.validate();
			if (form.isValid() == false)
				return;

			var data = form.getData(false, true);

			var temp = data.zhmytask.taskSendee;
			data.zhmytask.taskSendee = temp || ' ';

			data.zhmytask.taskDescibe = desc;

			var json = nui.encode(data);

			$.ajax({
				url : urlStr,
				type : 'POST',
				data : json,
				cache : false,
				contentType : 'text/json',
				success : function(text) {
					var returnJson = nui.decode(text);
					if (returnJson.exception == null) {
						nui.alert("保存任务成功", "提示");
						// CloseWindow("saveSuccess");
					} else {
						nui.alert("保存失败", "系统提示", function(action) {
							if (action == "ok" || action == "close") {
								// CloseWindow("saveFailed");
							}
						});
					}
				}
			});
		}

		//页面间传输json数据
		function setFormData(data) {
			//跨页面传递的数据对象，克隆后才可以安全使用
			var infos = nui.clone(data);

			//保存list页面传递过来的页面类型：add表示新增、edit表示编辑
			nui.getbyName("pageType").setValue(infos.pageType);

			//如果是点击编辑类型页面
			if (infos.pageType == "edit") {
				var json = infos.record;

				var form = new nui.Form("#dataform1");//将普通form转为nui的form
				form.setData(json);
				form.setChanged(false);

				nui.get("lookup2").setText(
						json.zhmytask.zhmyProject.projectName);

				// nui.get("lookup3").setText(json.CAP_PARTYAUTH.CapPartyauth.partyId);
				nui.get("lookup3").setText(json.zhmytask.taskSendee);

				$id("id1").setValue(json.zhmytask.taskDescibe);

			}
		}

		//关闭窗口
		function CloseWindow(action) {
			if (action == "close" && form.isChanged()) {
				if (confirm("数据被修改了，是否先保存？")) {
					saveData();
				}
			}
			if (window.CloseOwnerWindow)
				return window.CloseOwnerWindow(action);
			else
				window.close();
		}

		//确定保存或更新
		function onOk() {
			saveData();
		}

		//取消
		function onCancel() {
			//CloseWindow("cancel");
		}

		//my
		var grid = nui.get("datagrid1");
		var keyText = nui.get("keyText");
		grid.load();
		function onSearchClick(e) {
			grid.load({
				key : keyText.value
			});
		}

		function onCloseClick(e) {
			var lookup2 = nui.get("lookup2");
			lookup2.hidePopup();
		}

		function onClearClick() {
			var lookup2 = nui.get("lookup2");
			lookup2.deselectAll();
		}

		//my3
		var grid3 = nui.get("datagrid3");
		var keyText3 = nui.get("keyText3");
		grid3.load();
		function onSearchClick3(e) {
			grid3.load({
				key : keyText3.value
			});
		}

		function onCloseClick3(e) {
			var lookup3 = nui.get("lookup3");
			lookup3.hidePopup();
		}

		function onClearClick3() {
			var lookup3 = nui.get("lookup3");
			lookup3.deselectAll();
		}
		
		  		//选择办班的操作代码
        var grid5 = nui.get("datagrid5");
		var keyText5 = nui.get("keyText5");
		//grid5.load();
		grid5.load({
				key : keyText5.value ,
				projectid: outProjectid
			});
	 	function onSearchClick5(e) { 
			grid5.load({
				key : keyText5.value ,
				projectid: outProjectid
			});
		}
			
		function onCloseClick5(e) {
			var lookup2 = nui.get("lookup5");
			lookup2.hidePopup(); 
		}
			
		function onClearClick5() {
			var lookup2 = nui.get("lookup5");
			lookup2.deselectAll();
		}
		
	</script>
</body>
</html>
